<?php
/**
 * Created by PhpStorm.
 * User: 69571
 * Date: 2019/8/9
 * Time: 9:35
 */

namespace app\controllers;

use Yii;
use yii\filters\AccessControl;
use yii\web\Controller;
use yii\web\Response;
use yii\filters\VerbFilter;
use app\models\Rbac;
class RbacController extends  Controller{
    /**
     * @return false|string
     *  管理员添加
     */
    public function actionUsers_add(){
        $data = Yii::$app->request->post();
        $rbac = new Rbac;
        $insert_res = $rbac->insertUsers($data);
        return $insert_res;
    }
    /**
     *  修改管理员信息
     *
     */
    public function actionRole_update(){

        $data = Yii::$app->request->post();
        $rbac = new Rbac;
        $update_res = $rbac->updateUser($data);
        return $update_res;
    }
    /**
     *  修改管理员状态
     */
    public function actionChange_states(){
        $data = Yii::$app->request->post();
        $rbac = new Rbac;
        $changeStates = $rbac->changeStatus($data);
        return $changeStates;
    }
    /**
     *  删除
     *
     */
    public function actionUser_del(){
        $data = Yii::$app->request->post();
        $rbac = new Rbac;
        $delRes = $rbac->userDel($data);
        return $delRes;
    }

    /**
     *  添加角色
     *
     */
    public function actionAdmin_role_add(){
            $data = Yii::$app->request->post();
            $role_name = $data['role_name'];
            $role_remarks = $data['role_remarks'];
            $power_id = $data['power_id'];
            $insert_res = Yii::$app->db->createCommand("INSERT INTO role VALUES (null,'$role_name','$role_remarks')")->execute();
            if($insert_res){
                $role_id = Yii::$app->db->getLastInsertID();
                $u_p = Yii::$app->db->createCommand("INSERT INTO r_p VALUES ('$role_id','$power_id')")->execute();
                if($u_p){
                    echo "<script>alert('添加成功')</script>";
                }else{
                    echo "<script>alert('添加失败')</script>";
                }
            }
    }
    /**
     *
     * 修改角色的信息
     */
    public function actionChange_role(){
        $data = Yii::$app->request->post();
        $rbac = new Rbac;
        $change_res = $rbac->change_role($data);
        if($change_res){
            echo "<script>alert('修改成功')</script>";
        }
    }



}